<?php

class Controllers_BaseContent extends Zend_Controller_Action {
	public function init() {
		$name = $this->getFrontController()->getRequest()->getControllerName();
		$baseContentController = $this;
		$section = Manager::loadCache($name, function () use($baseContentController, $name) {
			return $baseContentController->getDbSection($name);
		});
		$this->view->parties = $section->getParties();
		$this->view->title = $section->getTitre();
	}

	public function indexAction() {
	}

	public function getDbSection($name) {
		$section = new Models_Utils_Section();

		$tableRubrique = Manager::getFactoryModel()->getRubrique();
		$rubrique = $tableRubrique->getRubriqueFromController($name);

		$tableArticle = Manager::getFactoryModel()->getArticle();
		$articles = $tableArticle->getArticlesFromRubrique($rubrique);

		$parties = array();
		foreach ($articles as $article) {
			$partie = new Models_Utils_Partie();
			$partie->setArticle($article);
			$partie->setImages($tableArticle->getImages($article));
			$partie->setLiens($tableArticle->getLiens($article));
			array_push($parties, $partie);
		}

		$section->setParties($parties);
		$section->setTitre($rubrique->titre);

		return $section;
	}
}

